<html>
<head>
<script src="js/mui.min.js"></script>
</head>
<body>
    
    <ion-view class="tzgg" hide-nav-bar="true"> 
    <ion-content class="erweima">
        <div class="module">
            <div class="content">               
                <div>
                    <div id="bcid"></div>
                </div>              
            </div>
        </div>
    </ion-content>  
<div class="fixbtn">    
        <span ng-click="cancelScanDo()"><i class="ion-ios-barcode-outline" id="cancelScan" ></i ><b>取消扫描</b></span>
    </div>
</ion-view>
<script>
ctr.controller('ScanCodeCtrl', ['$scope', '$location', 'dataService', '$window', '$ionicPopup', '$ionicBackdrop', function($scope, $location, dataService, $window, $ionicPopup, $ionicBackdrop) {
    setStyle();
    //mui初始化
    mui.init();
    //  mui.init({
    //      swipeBack: true //启用右滑关闭功能
    //  });
    var scan = null;
    var isOpen = false; // 闪光灯是否开始标志 true:闪光灯已经开启 false:闪光灯关闭
    // 条码识别成功事件
    function onmarked(type, result) {
        var text = '未知: ';
        switch(type) {
            case plus.barcode.QR:
                text = 'QR: '; // 二维码
                break;
            case plus.barcode.EAN13:
                text = 'EAN13: ';
                break;
            case plus.barcode.EAN8:
                text = 'EAN8: ';
                break;
        }
        alert(text + result);
        //关闭界面，返回首页
        scan.close(); //关闭扫描scan    
        $window.location.href = "#/tab/shouye";
    }
    // 创建扫描控件
    function startRecognize() {     
        scan = new plus.barcode.Barcode('bcid');
        //scan.start();     
        scan.onmarked = onmarked;
    }

    function setStyle() {       
        $("#bcid").width($(window).width());
        $("#bcid").height($(window).height() - 70);
    }

    // 开始扫描
    function StartDo() {
        startRecognize();
        scan.start();
    }
    //开始扫描
    $scope.$on('$ionicView.afterEnter', function() {  
        StartDo();
    })
    //取消扫描
    $scope.cancelScanDo = function() {
            if(scan != null) {
                scan.close(); //关闭扫描scan    
            }
            $window.location.href = "#/tab/shouye";
    }       
}])
</script>
</body>
</html>